﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VoicePhone.Common;

namespace VoicePhone.Utils
{
    public class SettingConfig : EntityClassXmlSerializer<SettingConfig>
    {
        public AppServer AppServer { get; set; }

        public static SettingConfig Load()
        {
            SettingConfig SettingConfig;
            string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config\\SettingConfig.xml");
            if (File.Exists(filePath))
            {
                string xmlStr = File.ReadAllText(filePath);
                SettingConfig = ReadFromXML(xmlStr);
            }
            else
            {
                if (!Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config")))
                    Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config"));
                SettingConfig = new SettingConfig();
            }

            if (SettingConfig.AppServer == null)
                SettingConfig.AppServer = new AppServer();

            return SettingConfig;
        }

        public void Save()
        {
            this.Save(ToXMLString(this), "SettingConfig.xml");
        }
    }

    public class AppServer
    {
        public string ServerIP { get; set; }
        public int ServerPort { get; set; }
        public int LocalPort { get; set; }
        public string LocalCallNo { get; set; } = "2001";
        public bool Instructor { get; set; }
        public string LocalLineId { get; set; }
        public string GroupNo { get; set; }
        public string CdrIP { get; set; } = "128.16.2.1";
    }
}
